package Exer9;

import java.util.Objects;

public class Student {
    // 5个字段：姓名、学号、年龄、专业、日期
    private String name;      // 字段1：姓名
    private String id;        // 字段2：学号
    private int age;          // 字段3：年龄
    private String major;     // 字段4：专业
    private String date;      // 字段5：日期

    // 构造函数：接收5个字段
    public Student(String name, String id, int age, String major, String date) {
        this.name = name;
        this.id = id;
        this.age = age;
        this.major = major;
        this.date = date;
    }

    // getter方法（必须保留，用于后续处理）
    public String getName() { return name; }
    public String getId() { return id; }
    public int getAge() { return age; }
    public String getMajor() { return major; }
    public String getDate() { return date; }

    // 重写toString，方便打印
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", id='" + id + '\'' +
                ", age=" + age +
                ", major='" + major + '\'' +
                ", date='" + date + '\'' +
                '}';
    }

    // 去重逻辑（按学号）
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
